<template>
  <div class="bank-container mtop">
    <m-header title="提现记录" :preventBack="true" @navback="$router.replace({path: '/mine'})">
      <span slot="right" class="shaixuan" @click="showPopup = true">筛选</span>
    </m-header>
    <div class="date-box">
      <div class="date-select" @click="showDateSelect">
        <div class="time">{{dateTimeVal | fmate}}</div>
        <div class="icon" :class="{'arrow': showDate}"></div>
      </div>
      <div class="allmoney">总计金额 ￥{{recordData.totalMoney || 0}}</div>
    </div>
    <div class="record-list">
      <div class="record-item" v-for="(item, index) in recordList" :key="index">
        <div class="types">
          <div class="type">{{item.bank_name}}</div>
          <div class="time">{{item.create_time}}</div>
        </div>
        <div class="status">{{item.status}}</div>
        <div class="money">￥{{item.money || 0}}</div>
      </div>
      <!-- <div class="record-item" v-for="(item, index) in 25" :key="index">
        <div class="types">
          <div class="type">微信充值</div>
          <div class="time">12月15日 20:57</div>
        </div>
        <div class="status">处理中</div>
        <div class="money">￥20</div>
      </div> -->
    </div>
    <div class="no-record" v-if="!recordList.length">
      <img src="../../../assets/imgs/icon-noattention@2x.png" alt="">
      <div class="desc">暂无数据</div>
    </div>
    <datetime
      :show="showDate"
      v-model="dateTimeVal"
      format="YYYY-MM"
      start-date="2018-01-01"
      :end-date="currentDate"
      @on-confirm="dateConfirm"
      @on-cancel="dateCancel"
      year-row="{value}年"
      month-row="{value}月"
    ></datetime>
    <popup v-model="showPopup">
      <div class="record-type">
        <div class="header">
          选择类型
          <span class="icon-del" @click="showPopup=false"></span>
        </div>
        <div class="types">
          <div class="state" v-for="(item, index) in  recordTypes" :key="index"
          :class="{'on':recordType==index}" @click="selectType(item.status, index)">{{item.text}}</div>
        </div>
        <div class="btn" @click="searchRecord">确定</div>
      </div>
    </popup>
  </div>
</template>
<script>
import { mapActions } from 'vuex';

export default {
  components: {
  },
  data () {
    return {
      showDate: false,
      showPopup: false,
      dateTimeVal: '',
      recordType: 0,
      recordTypes: [
        {
          id: 1,
          status: '',
          text: '全部状态'
        },
        {
          id: 2,
          status: 1,
          text: '支付成功'
        },
        {
          id: 3,
          status: 3,
          text: '处理中'
        }
      ],
      status: '',
      recordData: {},
      recordList: [
        // {
        //   'withdraw_id': '',
        //   'nickname': '嘻嘻啊',
        //   'status': '提现成功',
        //   'card_no': '6214835895312708',
        //   'account': '银行卡',
        //   'bank_name': '招商银行',
        //   'money': '99.00',
        //   'fee': '1.00',
        //   'create_time': '2018-12-29 23:11:28',
        //   'bank_info': '北京分行222',
        //   'modify_time': '2019-01-22 22:10:07'
        // },
        // {
        //   'withdraw_id': '',
        //   'nickname': '嘻嘻啊',
        //   'status': '提现成功',
        //   'card_no': '6214835895312708',
        //   'account': '银行卡',
        //   'bank_name': '招商银行',
        //   'money': '100.00',
        //   'fee': '0.00',
        //   'create_time': '2018-12-30 15:02:02',
        //   'bank_info': '北京分行222',
        //   'modify_time': '2019-01-22 22:36:33'
        // },
        // {
        //   'withdraw_id': '',
        //   'nickname': '嘻嘻啊',
        //   'status': '提现成功',
        //   'card_no': '6214835895312708',
        //   'account': '银行卡',
        //   'bank_name': '招商银行',
        //   'money': '100.00',
        //   'fee': '0.00',
        //   'create_time': '2018-12-30 15:03:11',
        //   'bank_info': '北京分行222',
        //   'modify_time': '2019-01-27 13:11:33'
        // }
      ]
    }
  },
  computed: {
    currentDate () {
      const date = new Date();
      const year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      month = month < 10 ? '0' + month : month;
      day = day < 10 ? '0' + day : day;
      return `${year}-${month}-${day}`
    }
  },
  filters: {
    fmate (val) {
      const _date = val.split('-');
      return `${_date[0]}年${_date[1]}月`;
    }
  },
  created () {
    this.dateTimeVal = this.currentDate.substring(0, 7);
  },
  mounted () {
    this.getWithdrawRecord();
  },
  methods: {
    ...mapActions({
      withdrawRecords: 'mine/withdrawRecords'
    }),
    getWithdrawRecord () {
      const start_time = this.dateTimeVal + '-01 00:00:00';
      const end_time = new Date().getTime();
      console.log(end_time)
      const params = {
        start_time: new Date(start_time).getTime() / 1000,
        end_time: parseInt(end_time / 1000), // 当前时间
        status: this.status // 1成功 2失败 3处理中
      }
      this.withdrawRecords(params).then(res => {
        if (res) {
          this.recordData = res;
          this.recordList = res.items || [];
          console.log('list', res);
        }
      });
    },
    selectType (status, index) {
      this.status = status;
      this.recordType = index;
    },
    searchRecord () {
      console.log(this.recordType);
      // 成功...
      this.showPopup = false;
      this.getWithdrawRecord();
    },
    showDateSelect () {
      this.showDate = true;
    },
    dateConfirm () {
      this.showDate = false;
      this.getWithdrawRecord();
      console.log('dateTimeVal', this.dateTimeVal)
    },
    dateCancel () {
      this.showDate = false;
    }
  }
}
</script>
<style lang="less" scoped>
  .bank-container {
    background: #f7f7f7;
    .date-box {
      position: fixed;
      top: 0.92rem;
      width: 100%;
      height: 1.06rem;
      padding: 0.14rem 0.2rem;
      box-sizing: border-box;
      background: #f7f7f7;
      z-index: 10;
      .date-select {
        display: inline-flex;
        align-items: center;
        height: 0.4rem;
        line-height: 0.4rem;
        box-sizing: border-box;
        .time {
          font-size: 0.28rem;
          color: #333333;
        }
        .icon {
          width: 0.24rem;
          height: 0.13rem;
          margin-left: 0.05rem;
          background-size: 0.24rem 0.13rem;
          background-repeat: no-repeat;
          background-image: url('../../../assets/imgs/mine/icon-down@2x.png')
        }
        .arrow {
          transform: rotate(180deg);
          transition: transform 0.4s;
        }
      }
      .allmoney {
        margin-top: 0.1rem;
        font-size: 0.22rem;
        color: #999999;
      }
    }
    .record-list {
      position: relative;
      top: 1.06rem;
      background: #ffffff;
      .record-item {
        position: relative;
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: 0.96rem;
        padding: 0 0.3rem 0 0.2rem;
        font-size: 0.28rem;
        color: #333333;
        &::after {
          content: "";
          display: block;
          position: absolute;
          bottom: 0;
          right: 0;
          width: 100%;
          height: 0.02rem;
          background: #d2d2d2;
          transform: scaleY(0.5);
        }
        .types {
          .type {
            margin-bottom: 0.1rem;
          }
          .time {
            font-size: 0.22rem;
            color: #999999;
          }
        }
        .status {}
        .money {
          font-size: 0.34rem;
          color: #D44743;
        }
      }
    }
    .no-record {
      position: fixed;
      width: 100%;
      top: 1.92rem;
      bottom: 0;
      height: 100%;
      text-align: center;
      background: #ffffff;
      img {
        display: block;
        width: 4.15rem;
        height: 3.22rem;
        margin: 0 auto;
        padding-top: 0.8rem;
      }
      .desc {
        margin-top: 0.3rem;
        font-size: 0.22rem;
        color: #919191;
      }
    }
    .vux-datetime {
      display: none;
    }
    .record-type {
      .header {
        position: relative;
        height: 0.8rem;
        line-height: 0.8rem;
        font-size: 0.32rem;
        color: #333333;
        text-align: center;
        &::after {
          content: "";
          display: block;
          position: absolute;
          bottom: 0;
          right: 0;
          width: 100%;
          height: 0.02rem;
          background: #d2d2d2;
          transform: scaleY(0.5);
        }
        .icon-del {
          position: absolute;
          right: 0.2rem;
          top: 0;
          width: 0.3rem;
          height: 0.3rem;
          padding: 0.25rem;
          background-image: url('../../../assets/imgs/icon-close@2x.png');
          background-size: 0.3rem 0.3rem;
          background-position: 50% 50%;
          background-repeat: no-repeat;
        }
      }
      .types {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.3rem 0.2rem;
        .state {
          width: 32.3%;
          height: 0.8rem;
          line-height: 0.8rem;
          font-size: 0.28rem;
          color: #333333;
          text-align: center;
          border: 1px solid #cd6c69;
          border-radius: 0.06rem;
          box-sizing: border-box;
          &.on {
            color: #ffffff;
            background: #d44743;
          }
        }
      }
      .btn {
        width: 100%;
        height: 1rem;
        line-height: 1rem;
        font-size: 0.34rem;
        color: #ffffff;
        text-align: center;
        background: #d44743;
      }
    }
  }
</style>
